<?php
class Admin_OrderController extends Apps_Controller_Action_Admin {

    public function readAction() {
        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        $select = $dbAdapter
                ->select()
                ->from('order', null)
                ->join('customer', 'customer.id = order.customer_id', null)
                ->join('product', 'product.id = order.product_id', null)
                ->joinLeft('order_status', 'order_status.id = order.order_status_id', null)
                ->joinLeft('payment_type', 'payment_type.id = order.payment_type_id', null)
                ->where('order.status =? ', Model_DbTable_Customer::STATUS_ACTIVE)
                ->columns(array(
                        'id'        => 'order.id',
                        'price'        => 'order.price',
                        'customer_id' => 'customer.id',
                        'full_name' => 'customer.full_name',
                        'email'     => 'customer.email',
                        'phone'     => 'customer.phone',
                        'address'   => 'customer.address',
                        'description'   => 'customer.description',
                        'payment_type' => 'payment_type.id',
                        'payment_type_title' => 'payment_type.title',
                        'order_status' => 'order_status.id',
                        'order_status_title' => 'order_status.title',
                        'product_name' => 'product.name',
                        'product_code' => 'product.code',
                        'product_price_sale' => 'product.price_sale',
                ));

        $grid = new Grid_Order_Order('grid-order');
        $grid->setCaption('List Order');
        $grid->setSource(new OeZend_Widget_Grid_Source_ZendDbSelect($select));
        $grid->setView(new OeZend_Widget_Grid_View());
        $grid->setDisablePaginator();

        $grid->deploy();

        $this->view->grid = $grid;
    }

    public function deleteAction() {
        $id = $this->_request->getParam('id');
        if(!$id) {
            $this->_redirect('read');
        }
        $tbOrder = new Model_DbTable_Order();
        $tbOrder->safelyUpdate(array('status' => Model_DbTable_Order::STATUS_DELETE), array('id =?' => $id));
        $this->_helper->redirector('read');
    }

}

